package com.qian.service;

import com.qian.dao.EmployeeMapper;
import com.qian.pojo.Employees;
import com.qian.utils.SnowFlake;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EmployeeService {

    @Resource
    private EmployeeMapper employeeMapper;

    //查询所有员工
    public List<Employees> queryAll(){
        return employeeMapper.queryAll();
    }

    //增加员工
    public void addEmployee(Employees employees){
        //雪花算法
        Long id = SnowFlake.nextId();
        employees.setEmployeeId(id);
        employeeMapper.addEmployee(employees);
    }

    //删除员工
    public void deleteEmployee(Long employeeId){
        employeeMapper.deleteEmployee(employeeId);
    }

    //更新员工
    public void updateEmployee(Employees employees){
        employeeMapper.updateEmployee(employees);
    }

    //通过ID查询员工
    public Employees selectEmployeeById(Long employeeId){
        return employeeMapper.selectEmployeeById(employeeId);
    }

    //通过姓名查询员工
    public List<Employees> queryEmployeeByName( String employeeName){
        return employeeMapper.queryEmployeeByName(employeeName);
    }

    public List<Employees> queryEmployeeByAccount(String employeeAccount){
        return employeeMapper.queryEmployeeByAccount(employeeAccount);
    }

    public List<Integer> allTenants(){
        List<Integer> list = employeeMapper.allTenants();
        if(!list.contains(1)){
            list.add(1);
        }
        if(!list.contains(2)){
            list.add(2);
        }
        if(!list.contains(3)){
            list.add(3);
        }
        if(!list.contains(4)){
            list.add(4);
        }
        return list;
    }
}
